package 蒙特卡洛;

import org.omg.CORBA.PUBLIC_MEMBER;

/**
 * @ClassName: Shape
 * @Auther: Drawin
 * @Date: 2021/10/7 16:14
 * @Description:
 */

public abstract class Shape{
    public abstract double getArea();
    public abstract double getPerimeter();

}
class Circle extends Shape{
    private double radius;
    private double getRadius(){return radius;}
    private void setRadius(double radius){this.radius=radius;}
    public Circle(double radius){this.radius=radius;}
    public double getArea(){
        return Math.PI*radius*radius;
    }
    public double getPerimeter(){
        return 2*Math.PI*radius;
    }
}

class Rectangle extends Shape{
    private double x,y;
    private double getX(){return x;}
    private void setX(double x){this.x=x;}
    private double getY(){return y;}
    private void setY(double y){this.y=y;}
    public Rectangle(double x,double y){
        this.x=x;
        this.y=y;
    }
    public double getArea(){
        return x*y;
    }
    public double getPerimeter(){
        return 2*(x+y);
    }
}

class MonteCarlo extends Shape{
    private double radius;
    private double getRadius(){return radius;}
    private void setRadius(double radius){this.radius=radius;}
    public MonteCarlo(double radius){
    final int N1=100000;
     int sum=0;
     for(int i=1;i<N1;i++){
        double x=Math.random();
        double y=Math.random();
        if((x*x+y*y)<radius)
            sum++;
     }
    }
     public double getArea(){return radius;}
    public double getPerimeter(){return radius;}
}//失败了，返回值返回不了sum/N1
